<template>
	<view>
		<view class="none" v-if="!authCodeUrl">
			暂无授权码
		</view>
		<view class="message" v-else>
			<img :src="authCodeUrl" alt="">
			<view class="text" @click="copy">
				复制授权地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mainid : "",
				authCodeUrl : "",
				authUrl : ""
			};
		},
		onShow() {
			var _this = this;
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
					console.log("_this.mainid",_this.mainid);
					_this.getSubject();
				}
			});
		},
		methods:{
			copy(){
				uni.setClipboardData({
					data: this.authUrl,
					success: function () {
						console.log('success');
					}
				});
			},
			getSubject(){
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/mchAuth/' + this.mainid, //仅为示例，并非真实接口地址。
					method: 'post',
					data: {
						id: this.mainid, //	用户ID（mainId）		true	string
					},
					success: (res) => {
						console.log('店铺信息：',res)
						if(res.data.status == 200){
							this.authCodeUrl = res.data.data.authCodeUrl;
							this.authUrl = res.data.data.authUrl;
							console.log(this.authCodeUrl);
							console.log(this.authUrl);
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.none{
		width: 100%;
		height: 500rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.message{
		height: 800rpx;
		display: flex;
		width: 100%;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.text{
		line-height: 100rpx;
		color: blue;
		font-size: 30rpx;
	}
</style>
